﻿@*@model IEnumerable<RBS.Core.Model.Sys_Links >*@

@{
    ViewBag.Title = "数据字典";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/scripts/mustache.js"></script>
<!--导航栏-->
<div class="location">
    <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
    <a href="@Url.Action("Main", "Home")" class="home"><i></i><span>首页</span></a>
    <i class="arrow"></i>
    <a href="@Url.Action("DictInfoIndex", "Sys")" ><span>数据字典</span></a>
    <i class="arrow"></i>
    <span>角色列表</span>
</div>
<!--/导航栏-->
<div style="float: left; width: 20%; padding-top: 15px;">
    <ul id="tt" class="easyui-tree" data-options="url:'@Url.Action("GetProvince")',method:'get',animate:true"></ul>
    <script>
        var pid = 0;
        var cid = 0; 
        $(document).ready(function () { 
            $('#tt').tree({
                onClick: function (node) {
                    treeLoad(node.id);
                    pid = node.id;
                    cid = 0;
                }
            });
            $("#dicinfoAdd").click(function () {
                if (pid == 0) {
                    alert("添加省份！");
                }
                if (pid > 0 && cid==0) {
                    AddCity(pid,0);
                }
                if (pid > 0 && cid > 0) {
                    AddCounty(cid,0);
                }  
            });
        }); 
        function AddCity(pid, id) { 
            $.dialog({
                id: 'city', lock: true, title: '城市信息维护', width: '620px', height: '250px', content: "url:@Url.Action("AddCity")?pid=" + pid +"&cid="+id/*, ok: function () {
                                orderid = 123;
                                this.reload();
                                return false;
                                    }   */
        });  
        }
        function AddCounty(cid,id) {
            $.dialog({
                id: 'county', lock: true, title: '区县信息维护', width: '710px', height: '520px', content: "url:@Url.Action("AddCounty")?cid=" + cid + "&ccid=" + id /*, ok: function () {
                                orderid = 123;
                                this.reload();
                                return false;
                                    }   */
            }); 
        }
      function treeLoad(dicParentId) {
                var url = "@Url.Action("GetCityInfoList")?parentId=" + dicParentId;
            $.ajax({
                url: url,
                type: 'Post',
                dataType: 'json',
                success: function (result) {
                    if (result == null)
                        return;
                    $("#dictinfo").empty();
                    $.each(result.Data, function (index, row) {
                        var template = $('#CityList').html(); //获取模版的html
                        var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                        $("#dictinfo").append(bookData);
                    });
                }
            });
            } 
        function CountyLoad(cityId) {
            cid = cityId;
            var url = "@Url.Action("GetCountyInfoList")?parentId=" + cityId;
             $.ajax({
                 url: url,
                 type: 'Post',
                 dataType: 'json',
                 success: function (result) {
                     if (result == null)
                         return;
                     $("#dictinfo").empty();
                     $.each(result.Data, function (index, row) {
                         var template = $('#CountyList').html(); //获取模版的html
                         var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                         $("#dictinfo").append(bookData);
                     });
                 }
             });
         }
       
        //删除
        function DelDictInfoChild(id) {
            var type = "";
            if (pid == 0) {
                alert("添加省份！");
            }
            if (pid > 0 && cid == 0) {
                type = "City";
            }
            if (pid > 0 && cid > 0) {
                type = "County"; 
            } 
            $.dialog.confirm("删除当前数据字典，会删除其子集<br/>删除后不可恢复，确认删除吗？", function () {
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '@Url.Action("DictInfoDelete")',
                    data: [  
                    { name: 'id', value: id },
                    { name: 'type', value: type }
                    ],
                    success: function (data) {
                        if (data.IsSuccess) {
                            // loadPage(data.Data);
                            $.dialog.alert("删除成功");
                            if(type =="City")
                                treeLoad(pid);
                            else {
                                CountyLoad(cid);
                            }
                        }
                        else { 
                            $.dialog.alert("删除失败"); 
                        }
                    }
                });
            });
            return false; 
        }
        //排序 
        function UpdateSeq(seq, id) {
            $.ajax({
                type: 'post', cache: false, dataType: 'json',
                url: '@Url.Action("UpdateSeq")',
                data: [
                    { name: 'ID', value: id },
                    { name: 'SEQ', value: seq }
                ],
                success: function (result) {
                    alert(result.Msg);
                    if (!result) {
                        return;
                    } else {
                        treeLoad();
                    }
                },
                error: function () {
                    return;
                }
            });
        }
        /*grid End*/
    </script>
</div>
<div style="float: right; width: 75%">
    <!--工具栏-->
    <div class="toolbar-wrap">
        <div id="floatHead" class="toolbar">
            <div class="l-list">
                <ul class="icon-list">
                    <li><a class="add" href="javascript:;" id="dicinfoAdd"><i></i><span>新增</span></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--/工具栏--> 
    <table width="98%" border="0" cellspacing="0" cellpadding="0" class="ltable">
        <tr> 
            <th align="center">名称</th> 
            <th width="20%">操作</th>
        </tr>
        <tbody id="dictinfo">
        </tbody>
    </table>
</div> 
<script type="text/template" id="CityList">
    <tr> 
        <td align="center">{{CityName}}
        </td>  
        <td align="center">
          <a href="javascript:;" onclick="CountyLoad({{Id}})"> 查看区县</a> |  <a href="javascript:;" onclick="AddCity({{ProvinceId}},{{Id}})">编辑</a>  | <a href="javascript:;" onclick="DelDictInfoChild({{Id}})">删除</a>
        </td>
    </tr>
</script>
<script type="text/template" id="CountyList">
    <tr> 
        <td align="center">{{CountyName}}
        </td>  
        <td align="center">
              <a href="javascript:;" onclick="AddCounty({{CityId}},{{Id}})">编辑</a> | <a href="javascript:;" onclick="DelDictInfoChild({{Id}})">删除</a>
        </td>
    </tr>
</script>

